package com.jason.campusinn.view;/*
package com.jason.campusinn.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yuandian.wanna.R;

*/
/**
 * 自定义头标题视图
 * 
 * @author Administrator
 * 
 *//*

public class TitleBar extends LinearLayout implements OnClickListener {
	private LinearLayout mLayoutLeft;
	private ImageView mIvLeft;
	private TextView mTvTitle;
	private RelativeLayout mLayoutRight;
	private ImageView mIvRight;
	private TextView mTvRight;

	private CharSequence mTitle;
	private Drawable mLeftDrawable;
	private Drawable mRightDrawable;
	private int mLeftVisibility = 0;
	private int mRightVisibility = 0;

	private OnClickListener mOnLeftClickListener;
	private OnClickListener mOnTitleClickListener;
	private OnClickListener mOnRightClickListener;

	public static final int TITLE_CLICK_ID = R.id.actionbar_tv_title;
	public static final int LEFT_CLICK_ID = R.id.actionbar_layout_left;
	public static final int RIGHT_CLICK_ID = R.id.actionbar_layout_right;

	public TitleBar(Context context) {
		this(context, null);
	}

	public TitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		if (isInEditMode()) {
			return;
		}
		View actionbar = LayoutInflater.from(context).inflate(
				R.layout.include_actionbar, null);
		addView(actionbar, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

		mLayoutLeft = (LinearLayout) findViewById(R.id.actionbar_layout_left);
		mIvLeft = (ImageView) findViewById(R.id.actionbar_iv_left);
		mTvTitle = (TextView) findViewById(R.id.actionbar_tv_title);
		mLayoutRight = (RelativeLayout) findViewById(R.id.actionbar_layout_right);
		mIvRight = (ImageView) findViewById(R.id.actionbar_iv_right);
		mTvRight = (TextView) findViewById(R.id.actionbar_tv_right);

		TypedArray array = context.getResources().obtainAttributes(attrs,
				R.styleable.actionbar);
		mTitle = array.getString(R.styleable.actionbar_title_bar_title);
		if (mTitle == null) {
			int titleResId = array.getResourceId(R.styleable.actionbar_title_bar_title,-1);
			if (titleResId != -1) {
				mTitle = getResources().getString(titleResId);
			}
		}

		mLeftVisibility = getVisibility(array.getInt(
				R.styleable.actionbar_left_visibility, 0));

		mLeftDrawable = getResources().getDrawable(
				array.getResourceId(R.styleable.actionbar_left_src,
						R.drawable.left_arraw_selector));

		mRightVisibility = getVisibility(array.getInt(
				R.styleable.actionbar_right_visibility, 2));

		mRightDrawable = getResources().getDrawable(
				array.getResourceId(R.styleable.actionbar_right_src,
						R.drawable.ic_action_nothing));

		array.recycle();

		initView();
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case LEFT_CLICK_ID:
			if (mOnLeftClickListener != null) {
				mOnLeftClickListener.onClick(mLayoutLeft);
			}
			break;
		case TITLE_CLICK_ID:
			if (mOnTitleClickListener != null) {
				mOnTitleClickListener.onClick(mTvTitle);
			}
			break;
		case RIGHT_CLICK_ID:
			if (mOnRightClickListener != null) {
				mOnRightClickListener.onClick(mLayoutRight);
			}
			break;
		}
	}

	private void initView() {
		setLeftImageDrawable(mLeftDrawable);
		setLeftVisibility(mLeftVisibility);
		setTitle(mTitle);
		setTitleClickable(false);
		setRightImageDrawable(mRightDrawable);
		setRightVisibility(mRightVisibility);
		mLayoutLeft.setOnClickListener(this);
		mTvTitle.setOnClickListener(this);
		mLayoutRight.setOnClickListener(this);
	}

	private int getVisibility(int visibility) {
		switch (visibility) {
		case 0:

			return View.VISIBLE;

		case 1:

			return View.INVISIBLE;

		case 2:

			return View.GONE;
		}
		return View.VISIBLE;
	}

	public TextView getTitleView() {
		return mTvTitle;
	}

	public ImageView getLeftView() {
		return mIvLeft;
	}

	public ImageView getRightView() {
		return mIvRight;
	}

	public void setLeftImageResource(int resId) {
		setLeftImageDrawable(getResources().getDrawable(resId));
	}

	public void setLeftImageBitmap(Bitmap bitmap) {
		setLeftImageDrawable(new BitmapDrawable(bitmap));
	}

	public void setLeftImageDrawable(Drawable drawable) {
		mLeftDrawable = drawable;
		mIvLeft.setImageDrawable(mLeftDrawable);
	}

	public void setLeftVisibility(int visibility) {
		if (visibility == View.VISIBLE || visibility == View.INVISIBLE
				|| visibility == View.GONE) {
			mLayoutLeft.setVisibility(visibility);
		}
	}

	public void setTitle(CharSequence s) {
		mTitle = s;
		mTvTitle.setText(s);
	}

	public void setTitleClickable(boolean clickable) {
		mTvTitle.setClickable(clickable);
		if (clickable) {
			mTvTitle.setTextColor(getResources().getColorStateList(
					R.color.main_text_color));
		} else {
			mTvTitle.setTextColor(getResources().getColor(R.color.main_text_color));
		}
	}

	public void setTitleLeft() {
		mTvTitle.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
	}

	public void setTitleCenter() {
		mTvTitle.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL);
	}

	public void setRightImageResource(int resId) {
		setRightImageDrawable(getResources().getDrawable(resId));
	}

	public void setRightImageBitmap(Bitmap bitmap) {
		setRightImageDrawable(new BitmapDrawable(bitmap));
	}

	public void setRightImageDrawable(Drawable drawable) {
		mRightDrawable = drawable;
		mIvRight.setImageDrawable(mRightDrawable);
	}

	public void setRightVisibility(int visibility) {
		if (visibility == View.VISIBLE || visibility == View.INVISIBLE
				|| visibility == View.GONE) {
			mLayoutRight.setVisibility(visibility);
		}
	}
	
	public void setRightText(String content){
		mTvRight.setText(content);
	}
	
	public void setRightTextVisibility(int visibility){
		if (visibility == View.VISIBLE || visibility == View.INVISIBLE
				|| visibility == View.GONE) {
			mTvRight.setVisibility(visibility);
		}
	}

	public void setOnLeftClickListener(OnClickListener listener) {
		mOnLeftClickListener = listener;
	}

	public void setOnTitleClickListener(OnClickListener listener) {
		mOnTitleClickListener = listener;
	}

	public void setOnRightClickListener(OnClickListener listener) {
		mOnRightClickListener = listener;
	}
}
*/
